package com.etone.smartAudit.mapstruct;

import com.etone.smartAudit.domain.Item;
import com.etone.smartAudit.domain.ItemExpansion;
import com.etone.smartAudit.domain.ItemExpansionSource;
import com.etone.smartAudit.domain.ItemSource;
import com.etone.smartAudit.dto.item.ItemDTO;
import com.etone.smartAudit.dto.item.ItemExpansionDTO;
import com.etone.smartAudit.dto.item.ItemExpansionSourceDTO;
import com.etone.smartAudit.vo.item.*;
import org.mapstruct.*;

import java.util.List;

/**
 * @author: 蒋学伟
 * @create: 2020-07-17 08:27:49
 * @Description itemMapstruct
 */

@Mapper(componentModel = "spring", nullValueCheckStrategy = NullValueCheckStrategy.ALWAYS, imports = {com.etone.smartAudit.vo.FileVO.class, com.alibaba.fastjson.JSONArray.class, com.alibaba.fastjson.JSON.class})
public interface ItemMapstruct {

    void copyToItem(@MappingTarget Item item, ItemDTO itemDTO);

    void copyToItemExpansion(@MappingTarget ItemExpansion itemExpansion, ItemExpansionDTO itemExpansionDTO);

    void copyToItemExpansionSource(@MappingTarget ItemExpansionSource itemExpansionSource, ItemExpansionSourceDTO itemExpansionSourceDTO);

    void copyToItemExpansionSource(@MappingTarget List<ItemExpansionSource> itemExpansionSources, List<ItemExpansionSourceDTO> itemExpansionSourceDTOS);

    ItemBaseVO getItemBaseVO(Item item);

    ItemDetailVO getItemDetailVO(Item item);

    ItemSourceBaseVO getItemSourceBaseVO(ItemSource itemSource);

    List<ItemSourceBaseVO> getItemSourceBaseVO(List<ItemSource> itemSources);

    @Mappings({
            @Mapping(
                    target = "files",
                    expression = "java(itemSource.getFiles()==null||itemSource.getFiles()==\"\"?null:JSONArray.parseArray(itemSource.getFiles(),FileVO.class))"
            ),
            @Mapping(
                    target = "cover",
                    expression = "java(itemSource.getCover()==null||itemSource.getCover()==\"\"?null:JSON.parseObject(itemSource.getCover(),FileVO.class))"
            )
    })
    ItemSourceDetailVO getItemSourceDetailVO(ItemSource itemSource);

    ItemExpansionSource getItemExpansionSource(ItemExpansionSourceVO itemExpansionSourceVO);

}
